package subject_set.interview.Day1_31_huiliang;

/**
 * @author haomin
 * @date 2023/01/31 13:40
 **/
import java.util.*;

public class Main {
    public static ArrayList<ArrayList<Integer>> res = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> permute(int[] num) {
        boolean[] flag = new boolean[num.length];
        fun(num, 0, num.length - 1, flag, new ArrayList<>());
        return res;
    }
    public static void fun(int[] num, int l, int r, boolean[] flag, ArrayList<Integer> list) {
        if(list.size() == r+1) {
            res.add(new ArrayList<>(list));
            return;
        }

        for(int i = 0; i <= r; ++i) {
            if(flag[i]) continue;
            flag[i] = true;
            list.add(num[i]);
            fun(num, i+1, r, flag, list);
            list.remove(list.size()-1);
            flag[i] = false;
        }
    }
}